package cn.csust.net2.manager.server.remote;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;

import cn.csust.net2.manager.server.dao.BaseDAO;
public class BeanUtils {
	/**
	 * 单例，在REMOVESERVLET中初始化（需要验证单态）
	 */
	public static WebApplicationContext applicationContext;
	
	
	//测试用的SPRING环境
	public static ApplicationContext act;
	@SuppressWarnings("unchecked")
	public static <T>  BaseDAO<T>  getBean(String cla){
		String s [] =cla.split("\\.");
//		for(int i=0;i<s.length;i++)
//			System.out.println(s[i]);
	//	System.out.println(s[s.length-1]+"DAO");
		if(BeanUtils.applicationContext==null){
			BaseDAO<T> t = (BaseDAO<T>) act.getBean(s[s.length-1]+"DAO");
			return t;
		}else{
			BaseDAO<T> t = (BaseDAO<T>) applicationContext.getBean(s[s.length-1]+"DAO");
			return t;
		}
	}
}
